/*    */ package com.liy.cloud.auth.client.aop;
/*    */ 
/*    */ import com.das.framework.common.utils.ContextHandler;
/*    */ import feign.RequestInterceptor;
/*    */ import feign.RequestTemplate;
/*    */ import java.util.Enumeration;
/*    */ import java.util.LinkedHashMap;
/*    */ import java.util.Map;
/*    */ import javax.servlet.http.HttpServletRequest;
/*    */ import org.slf4j.Logger;
/*    */ import org.slf4j.LoggerFactory;
/*    */ import org.springframework.beans.factory.annotation.Value;
/*    */ import org.springframework.context.annotation.Configuration;
/*    */ import org.springframework.web.context.request.RequestContextHolder;
/*    */ import org.springframework.web.context.request.ServletRequestAttributes;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ @Configuration
/*    */ public class FeignInterceptorService
/*    */   implements RequestInterceptor
/*    */ {
/* 36 */   private Logger log = LoggerFactory.getLogger(FeignInterceptorService.class);
/*    */ 
/*    */ 
/*    */ 
/*    */   
/*    */   @Value("${dascloud.authrization.enabled: true}")
/*    */   private Boolean enabled;
/*    */ 
/*    */ 
/*    */   
/*    */   @Value("${dascloud.authrization.token-header:JwtToken}")
/*    */   private String tokenHeader;
/*    */ 
/*    */ 
/*    */   
/*    */   @Value("${dascloud.authrization.auth-key:AuthKey}")
/*    */   private String authKeyHeader;
/*    */ 
/*    */ 
/*    */ 
/*    */   
/*    */   public void apply(RequestTemplate requestTemplate) {
/* 58 */     if (!this.enabled.booleanValue())
/*    */       return; 
/* 60 */     this.log.debug("Add authentication key to feign request: " + this.tokenHeader + ":" + this.authKeyHeader);
/* 61 */     this.log.debug(ContextHandler.getJwtToken());
/*    */ 
/*    */     
/* 64 */     requestTemplate.header(this.tokenHeader, new String[] { ContextHandler.getJwtToken() });
/* 65 */     requestTemplate.header(this.authKeyHeader, new String[] { ContextHandler.getAuthKey() });
/*    */   }
/*    */ 
/*    */   
/*    */   private HttpServletRequest getHttpServletRequest() {
/*    */     try {
/* 71 */       return ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
/* 72 */     } catch (Exception e) {
/* 73 */       e.printStackTrace();
/* 74 */       return null;
/*    */     } 
/*    */   }
/*    */ 
/*    */   
/*    */   private Map<String, String> getHeaders(HttpServletRequest request) {
/* 80 */     Map<String, String> map = new LinkedHashMap<String, String>();
/* 81 */     Enumeration<String> enumeration = request.getHeaderNames();
/* 82 */     while (enumeration.hasMoreElements()) {
/* 83 */       String key = (String)enumeration.nextElement();
/* 84 */       String value = request.getHeader(key);
/* 85 */       map.put(key, value);
/*    */     } 
/* 87 */     return map;
/*    */   }
/*    */ }


/* Location:              C:\Users\admin\Desktop\Jar\das-cloud-osc\das-cloud-osc-auth-client-1.0.0-SNAPSHOT.jar!\com\das\cloud\auth\client\aop\FeignInterceptorService.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.0.7
 */